define(['helper/tools'],function(tools){
	var _this = null;
		// $transArea = $(".trans_area");
	var init = function(){
		_this = this;
		// _this.view.init();
		_this.getTrans();
	};
	var getTrans = function(){
		tools.ajax('translate',
			{
				word:tools.__UTILS.userActionRecord.transWord
			},
			function(res){
				if(res.status == 1){
					tools.__UTILS.getTransRes = res;
				}
				else{
					tools.__UTILS.getTransRes = {"word":tools.__UTILS.userActionRecord.transWord,"cn_trans":""}
				}
								
			}				
		)
		// tools.__UTILS.getTransRes ={"word":"haah","cn_trans":"哈哈"};
		
	};
	var view = {
		init: function(){
			$(".trans_area_word").html(tools.__UTILS.getTransRes.word);
			$(".cn_trans").html(tools.__UTILS.getTransRes.cn_trans);
			view.transStyle();
			$(".trans_area").show();

		},
		transStyle: function(){
			if(tools.__UTILS.appearance.word_pos.top > 140){
				$(".trans_area").css({
					// "left" : tools.__UTILS.appearance.word_pos.left + 0.5*tools.__UTILS.appearance.word_width-0.5*$(".trans_area").width(),
					// "top" : tools.__UTILS.appearance.word_pos.top + tools.__UTILS.appearance.word_height +8,
					"left" : tools.__UTILS.appearance.word_pos.left + 0.5*tools.__UTILS.appearance.word_width-0.5*$(".trans_area").width(),
					"top" : tools.__UTILS.appearance.word_pos.top - $(".trans_area").height()-10
				});
			}
			else{
				$(".trans_area").css({
					"left" : tools.__UTILS.appearance.word_pos.left + 0.5*tools.__UTILS.appearance.word_width-0.5*$(".trans_area").width(),
					"top" : tools.__UTILS.appearance.word_pos.top + tools.__UTILS.appearance.word_height +8
				});
			}
		}
	};
	var regBtn = {
		turnDifficulty: function(){
			$(".e_a_s_y").removeClass("choose_easy");
			$(".h_a_r_d").addClass("choose_hard")
		},
		turnEasy: function(){
			$(".h_a_r_d").removeClass("choose_hard");
			$(".e_a_s_y").addClass("choose_easy");
		},
		removeDot: function(){
			require(['pageReading'], function(pageReading) {
                    pageReading.view.unDotWord();
                    pageReading.view.initByTrans();
            });
		},
		addDot: function(){
			require(['pageReading'], function(pageReading) {
                    pageReading.view.dotWord(tools.__UTILS.userActionRecord.transWordId,tools.__UTILS.getTransRes.cn_trans);
                    pageReading.view.initByTrans();
            });			
		},
		init: function(){
			$(".e_a_s_y").click(function(){
				tools.__UTILS.userActionRecord.choose_easy = 1;
				regBtn.turnEasy();
				regBtn.removeDot();
			});
			$(".h_a_r_d").click(function(){
				tools.__UTILS.userActionRecord.choose_easy = 0;
				regBtn.turnDifficulty();
				if($('[data-trans_id="'+tools.__UTILS.userActionRecord.transWordId+'"]').length == 0 ){
					regBtn.addDot();
				}

			});
			$(".trans_area").mouseleave(function(){
				
				tools.__UTILS.userActionRecord.enterTransArea = 0;
				console.log("鼠标离开翻译框");
				$(this).hide();
				// require(['pageReading'], function(pageReading) {
    //                 pageReading.view.removeWordMouseLeaveEvent();
                            
    //         	});
			});
			$(".trans_area").mouseenter(function(){
				tools.__UTILS.userActionRecord.enterTransArea = 1;
				console.log("鼠标进翻译框");

			});
		
		}
	};
	return{
		init: init,
		getTrans:getTrans,
		regBtn: regBtn,
		view: view,
		// pageReading: pageReading
	}

})